Watch as we step through the algorithm: dequeue a node, process it, and enqueue its unvisited neighbors.

  • The process begins by dequeuing the start node 'A'. Its status changes from "discovered" to "processed".
  • 'A's neighbors, 'B' and 'C', are unvisited, so they are marked "discovered" and enqueued.
  • Next, 'B' is dequeued and processed. Its unvisited neighbors, 'D' and 'F', are discovered and enqueued.
  • 'C' is then dequeued and processed, leading to 'E' being discovered and enqueued.
  • The remaining nodes are dequeued, but since all their neighbors have already been discovered, no new nodes are added to the queue.
  • The key takeaway is observing how the queue manages the frontier of discovered nodes, ensuring a level-by-level exploration.
Step Dequeue Enqueue Queue After
1AB, C[B, C]
2BD, F[C, D, F]
3CE[D, F, E]
4D[F, E]
5F[E]
6E[]